﻿
Partial Class Interfaz_frmAdminProveedores
    Inherits System.Web.UI.Page
    Dim CL As New ControladorLogica

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If CL.visibilidadesFormsInternos("Administracion", Session("user").ToString) = False Then
            Response.Redirect("Index.aspx")
        End If

    End Sub

#Region "funcionalidades"
    Public Sub Mensaje(ByVal msg As String)
        Dim alertScript As String = "<script language=JavaScript runat=server>"
        alertScript &= "alert('" & msg & "');"
        alertScript &= "</script>"
        ClientScript.RegisterClientScriptBlock(Page.GetType(), "clientScrip", alertScript)
    End Sub

    Private Sub InsertarCliente()
        Dim rut As String = Me.TxtRut.Text + "-" + Me.TxtDV.Text
        Dim compañia As String = Me.TxTcompañia.Text
        Dim contacto As String = Me.TxtContacto.Text
        Dim telefono As String = Me.TxtTelefono.Text
        Dim email As String = Me.TxtEmail1.Text + "@" + Me.TxtEmail2.Text
        Dim giro As String = Me.TxtGiro.Text
        Dim direccion As String = Me.TxtDireccion.Text
        Dim region As String = Me.TxtRegion.Text
        Dim ciudad As String = Me.TxtCiudad.Text
        Dim fax As String = Me.TxtFax.Text
        Dim comuna As String = Me.TxtComuna.Text
        Dim cliente As Cliente
        Dim proveedor As Proveedor

        If rut <> "" And compañia <> "" And contacto <> "" And telefono <> "" And email <> "" And giro <> "" And _
           direccion <> "" And region <> "" And ciudad <> "" And fax <> "" And comuna <> "" Then
            proveedor = New Proveedor(rut, compañia, direccion, giro, telefono, comuna, region, contacto, ciudad, fax, email)
            CL.InsertarProveedor(proveedor)

            If Me.RBCliente.Checked = True Then
                cliente = New Cliente(rut, compañia, direccion, giro, telefono, comuna, region, contacto, ciudad, fax, email, 0)
                CL.InsertarCliente(cliente)
            End If

            Me.Mensaje("Los datos han sido ingresados exitosamente")

        Else
            Me.Mensaje("Debe Rellenar todos los campos para ingresar un cliente ")
        End If
    End Sub
    Private Sub Limpiar()
        TxtRut.Text = String.Empty
        TxtDV.Text = String.Empty
        TxTcompañia.Text = String.Empty
        TxtContacto.Text = String.Empty
        TxtTelefono.Text = String.Empty
        TxtEmail1.Text = String.Empty
        TxtEmail2.Text = String.Empty
        TxtGiro.Text = String.Empty
        TxtDireccion.Text = String.Empty
        TxtRegion.Text = String.Empty
        TxtCiudad.Text = String.Empty
        TxtFax.Text = String.Empty
        TxtComuna.Text = String.Empty
    End Sub
#End Region

#Region "Botones"

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        Limpiar()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        InsertarCliente()
    End Sub
#End Region
End Class
